package com.ly.base.chapter02.AAAFuncCitation;


import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.function.IntBinaryOperator;
import java.util.function.IntPredicate;
import java.util.function.Supplier;

/**
 * 函数接口归类
 *
 * 可以利用泛型来定义接口方法：形参 和 返回值 类型都可以(有自动推断机制的：有些类型可以省略)
 */
public class Demo01 {

    public static void main(String[] args) {
       Type1 type1 =  (int a) -> (a & 1) == 0;
       IntPredicate obj1 = (int a) -> (a & 1) == 0;//利用jdk提供的接口

       Type1 type2 = (int a) -> BigInteger.valueOf(a).isProbablePrime(100);

       Type2 type3 = (int a,int b,int c) -> a + b + c;

        Type3 type4 = (int a,int b) -> a -b;
        IntBinaryOperator obj4 = (int a,int b) -> a -b;//利用jdk提供的接口
        Type3 type5 =(int a,int b) -> a * b;
        IntBinaryOperator obj5 = (int a,int b) -> a * b;//利用jdk提供的接口

        TypeTTT<Student> type6 = () -> new Student();
        Supplier<Student> obj6 =  () -> new Student();//利用jdk提供的接口
        TypeTTT<List<Student>> type7 = () -> new ArrayList<Student>();
        Supplier<List<Student>> obj7 =  () -> new ArrayList<Student>();//利用jdk提供的接口


        Type7<String> type8 = (Student s) -> s.getName();
        Type7<Integer> type9 = (Student s) -> s.getAge();
        Function<Student,String> obj8 = student -> student.getName();//利用jdk提供的接口
        Function<Student,Integer> obj9 = student -> student.getAge();//利用jdk提供的接口

    }




    //定义接口
    @FunctionalInterface//编译期间检查：接口中是否有且仅有一个抽象方法
    interface Type1{
        boolean op(int a);
    }

    @FunctionalInterface
    interface Type2{
        int op(int a,int b,int c);
    }

    @FunctionalInterface
    interface Type3{
        int op(int a,int b);
    }

    @FunctionalInterface
    interface Type4{
        Student op();
    }

    @FunctionalInterface
    interface Type5{
        ArrayList<String> op();
    }

    //使用泛型扩展函数式接口
    @FunctionalInterface
    interface TypeTTT<T>{
        T op();
    }

     interface Type7<T>{
        T op(Student s);
     }

}
